﻿@inherits ClientSectionCompontentBase

<MItemGroup Mandatory>
    <div class="d-flex justify-space-between">
        @foreach (var _clientType in _clientTypes)
        {
            <MCol @key="_clientType.ClientType">
                <MItem>
                    <MCard Color="@(context.Active ? "hover-background" : "")" Height="244"
                       OnClick="()=>{ context.Toggle();TypeChanged.InvokeAsync(_clientType.ClientType); }">
                        <MCardTitle Class="d-flex justify-center h5">
                            <SIcon Size=24 Class="mr-2">@_clientType.Icon</SIcon> @T(_clientType.ClientType.ToString())
                        </MCardTitle>
                        <MCardText>
                            @_clientType.Description
                        </MCardText>
                    </MCard>
                </MItem>
            </MCol>
        }
    </div>
</MItemGroup>

@code {
    [Parameter]
    public ClientTypes Type { get; set; } = ClientTypes.Web;

    [Parameter]
    public EventCallback<ClientTypes> TypeChanged { get; set; }

    List<ClientTypeDetailDto> _clientTypes = new List<ClientTypeDetailDto>();
    ClientService ClientService => AuthCaller.ClientService;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            _clientTypes = await ClientService.GetClientTypeListAsync();
            StateHasChanged();
        }
        await base.OnAfterRenderAsync(firstRender);
    }
}
